SWEP.Author				= "Dark Moule/Team Garry/kevkev(Warrior xXx)"
SWEP.Contact			= "http://forums.facepunchstudios.com/showthread.php?t=537191"
SWEP.Purpose			= "Killing the enemy"
SWEP.Instructions		= "Left click to fire"
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= false
SWEP.PrintName			= "Egon"
SWEP.Category 			= "Egons"
SWEP.Slot				= 3
SWEP.SlotPos			= 7
SWEP.DrawAmmo			= false
SWEP.DrawCrosshair		= true
SWEP.ViewModel			= "models/lazergun2.mdl"
SWEP.WorldModel			= "models/weapons/w_physics.mdl"

local sndPowerUp		= Sound("Airboat.FireGunHeavy")
local sndAttackLoop 	= Sound("Airboat_fan_idle")
local sndPowerDown		= Sound("Town.d1_town_02a_spindown")

function SWEP:Initialize()
	self:SetWeaponHoldType("smg")
end

function SWEP:Think()
	if !self.Owner or self.Owner == NULL then return end
	if self.Owner:KeyPressed(IN_ATTACK) then
		self:StartAttack()
	elseif self.Owner:KeyDown(IN_ATTACK) then
		self:UpdateAttack()
	elseif self.Owner:KeyReleased(IN_ATTACK) then
		self:EndAttack(true)
	end
end

function SWEP:StartAttack()
	if SERVER then
		if !self.Beam then
			self.Beam = ents.Create("egon_beam")
			self.Beam:SetPos(self.Owner:GetShootPos())
			self.Beam:Spawn()
		end
		self.Beam:SetParent(self.Owner)
		self.Beam:SetOwner(self.Owner)
	end
	self:UpdateAttack()
end

function SWEP:UpdateAttack()
	if self.Timer and self.Timer > CurTime() then return end
	self.Timer = CurTime()+0.05
	self.Owner:LagCompensation(true)
	local st = self.Owner:GetShootPos()
	local en = st+(self.Owner:GetAimVector()*4096)
	local fl = {self.Owner,self.Weapon}
	local tr = Egon_GetTraceData(st,en,fl)
	local ent = tr.Entity
	if SERVER then
		if ValidEntity(ent) then
			if ent:GetClass() == "shield" then
				ent:Hit(self.Weapon,tr.HitPos,0.5,-1*tr.Normal)
			end
		end
	end
	if SERVER and self.Beam then
		self.Beam:GetTable():SetEndPos(tr.HitPos)
	end
	util.BlastDamage(self.Weapon,self.Owner,tr.HitPos,80,5)
	if ent and ent:IsPlayer() and !tr.HitSky then
		local effectdata = EffectData()
		effectdata:SetEntity(ent)
		effectdata:SetOrigin(tr.HitPos)
		effectdata:SetNormal(tr.HitNormal)
		util.Effect("bodyshot",effectdata)
	end
	self.Owner:LagCompensation(false)
end

function SWEP:EndAttack(a)
	self.Weapon:StopSound(sndAttackLoop)
	if a then
		self.Weapon:EmitSound(sndPowerDown)
	end
	if CLIENT then return end
	if !self.Beam then return end
	self.Beam:Remove()
	self.Beam = nil
end

function SWEP:Holster()
	self:EndAttack(false)
	return true
end

function SWEP:OnRemove()
	self:EndAttack(false)
	return true
end

function SWEP:PrimaryAttack()
	self.Weapon:EmitSound(sndPowerUp)
	self.Weapon:EmitSound(sndAttackLoop)
end

function SWEP:SecondaryAttack()
end